const assert = require("assert");
const koffi = require("koffi");

const lib = koffi.load("/my-lib/libapi.so");

const howManyCharactersFunc = lib.func("int32 how_many_characters(const char *)");

const result = howManyCharactersFunc("rust");
console.log("Result: %s", result);
assert(4 === result);

testApi();

function testApi() {
    function assertHowManyCharacters(text, expectedResult) {
        const result = howManyCharactersFunc(text);

        assert(expectedResult === result);
    }

    assertHowManyCharacters(null, -1);
    assertHowManyCharacters("", 0);
    assertHowManyCharacters("rust", 4);
}
